package cn.hss.loop;

import java.util.Scanner;

/**猜数字小游戏
 * @author 作者：HeShaoShuai
 * @Email 邮箱：2569819541@qq.com
 * @Date 日期：2023/4/25 16:50
 * @Package 包名：cn.hss.loop
 * @Project 项目名：JavaSE
 * @Version 1.0
 */
public class doWhileDemo1 {
	public static void main(String[] args) {
		//获取一个随机数,做为比较的目标值
		int num=(int)(Math.random()*100)+1;
		System.out.println(num);
		//记录猜的次数
		int count=1;
		Scanner sca = new Scanner(System.in);
		System.out.println("请输入一个整数(1-100)：");
		int guess = sca.nextInt();
		do{
			if(guess>num){
				System.out.println("猜大了");
			}else if(guess<num){
				System.out.println("猜小了");
			}
			System.out.println("请输入一个整数(1-100)：");
			guess = sca.nextInt();
			//累加猜的次数
			count++;
		}while(guess != num);
		System.out.println("恭喜你，猜对了！！！");
		System.out.println("共猜了"+count+"次");
	}
}
